DEFINITION FOR LIBRARY MODULE DiskFont ;

FROM SYSTEM	IMPORT BADDRESS, ADDRESS, SHORTSET, STRING, LONGSET ;
FROM Exec	IMPORT Node, LibraryPtr ;
FROM Graphics	IMPORT TextAttr, TextAttrPtr, TextFont, TTextAttr, TextFontPtr ;
FROM Dos	IMPORT FileLockPtr ;
FROM Utility	IMPORT TagItemPtr ;

(* diskfont library definitions *)

TYPE
  FontContentsPtr	= POINTER TO FontContents	;
  TFontContentsPtr	= POINTER TO TFontContents	;
  FontContentsHeaderPtr	= POINTER TO FontContentsHeader ;
  DiskFontHeaderPtr	= POINTER TO DiskFontHeader	;
  AvailFontsPtr		= POINTER TO AvailFontsRec	;
  TAvailFontsPtr	= POINTER TO TAvailFonts	;
  AvailFontsHeaderPtr	= POINTER TO AvailFontsHeader	;

CONST
  MAXFONTPATH = 256 ;   (* including null terminator *)

TYPE
  FontContents = RECORD
    fc_FileName : ARRAY [0..MAXFONTPATH-1] OF CHAR ;
    fc_YSize	: CARDINAL ;
    fc_Style	: SHORTSET ;
    fc_Flags	: SHORTSET ;
  END ;

  TFontContents = RECORD
    tfc_FileName : ARRAY [0..MAXFONTPATH-3] OF CHAR ;
    tfc_TagCount : CARDINAL ;	(* including the TAG_DONE tag *)

     (*	if tfc_TagCount is non-zero, tfc_FileName is overlayed with   *)
     (*	Text Tags starting at:	TagItemPtr			      *)
     (*	  ADR(tfc_FileName[MAXFONTPATH-(tfc_TagCount*SIZE(TagItem))]) *)

    tfc_YSize : CARDINAL ;
    tfc_Style : SHORTSET ;
    tfc_Flags : SHORTSET ;
  END ;

CONST
  FCH_ID  = 00F00H ; (* FontContentsHeader, then FontContents   *)
  TFCH_ID = 00F02H ; (* FontContentsHeader, then TFontContents  *)
  OFCH_ID = 00F03H ; (* FontContentsHeader, then TFontContents, *)
		     (* associated with outline font		*)

TYPE
  FontContentsHeader = RECORD
    fch_FileID	   : CARDINAL ;	(* FCH_ID				*)
    fch_NumEntries : CARDINAL ;	(* the number of FontContents elements	*)
    (* struct FontContents fch_FC[], or struct TFontContents fch_TFC[]; *)
  END ;

CONST
   DFH_ID	= 00F80H ;
   MAXFONTNAME	= 32 ;	(* font name including ".font\0" *)

TYPE
  DiskFontHeader = RECORD
    (* the following 8 bytes are not actually considered a part of the	*)
    (* DiskFontHeader, but immediately preceed it. The NextSegment is	*)
    (* supplied by the linker/loader, and the ReturnCode is the code	*)
    (* at the beginning of the font in case someone runs it...		*)
    (*	 ULONG dfh_NextSegment;			\* actually a BPTR	*)
    (*	 ULONG dfh_ReturnCode;			\* MOVEQ #0,D0 : RTS	*)
    (* here then is the official start of the DiskFontHeader...		*)

    dfh_DF       : Node ;	(* node to link disk fonts	   *)
    dfh_FileID   : CARDINAL ;	(* DFH_ID			   *)
    dfh_Revision : CARDINAL ;	(* the font revision		   *)

    CASE :LONGINT OF
    |0 :dfh_Segment : BADDRESS ;	(* the segment address when loaded *)
    |1 :dfh_TagList : TagItemPtr ; 	(* destroyed during loading	   *)
    					(* used only if dfh_TF.tf_Style    *)
    					(* FSB_TAGGED bit is set	   *)
    END ;
    dfh_Name : ARRAY [0..MAXFONTNAME-1] OF CHAR ;
    				(* the font name (null terminated) *)
    dfh_TF    : TextFont ;	(* loaded TextFont structure	   *)
  END ;

CONST
  AFB_MEMORY	=  0 ; AFF_MEMORY = {0} ;
  AFB_DISK	=  1 ; AFF_DISK	  = {1} ;
  AFB_SCALED	=  2 ; AFF_SCALED = {2} ;
  AFB_BITMAP	=  3 ; AFF_BITMAP = {3} ;

  AFB_TAGGED	= 16 ; AFF_TAGGED = {16}; (* return TAvailFonts *)


TYPE
  AvailFontsRec = RECORD
    af_Type : BITSET   ;	(* MEMORY, DISK, or SCALED  *)
    af_Attr : TextAttr ;	(* text attributes for font *)
  END ;

  TAvailFonts = RECORD
    taf_Type : BITSET  ;	(* MEMORY, DISK, or SCALED  *)
    taf_Attr : TTextAttr ;	(* text attributes for font *)
  END ;

  AvailFontsHeader = RECORD
    afh_NumEntries : CARDINAL ;	(* number of AvailFonts elements *)
    (* struct AvailFonts afh_AF[], or struct TAvailFonts afh_TAF[]; *)
  END ;

VAR
  DiskfontBase : LibraryPtr ;

PROCEDURE OpenDiskFont( textAttr : TextAttrPtr ) : TextFontPtr ;

PROCEDURE AvailFonts( buffer   : STRING ;
		      bufBytes : LONGINT ;
		      flags    : LONGSET ) : LONGINT ;

(*--- functions in V34 or higher (Release 1.3) ---*)

PROCEDURE NewFontContents( fontsLock : FileLockPtr ;
			   fontName  : STRING ) : FontContentsHeaderPtr ;

PROCEDURE DisposeFontContents( fontContentsHeader : FontContentsHeaderPtr ) ;

(*--- functions in V36 or higher (Release 2.0) ---*)

PROCEDURE NewScaledDiskFont( sourceFont   : TextFontPtr ;
			     destTextAttr : TextFontPtr ) : DiskFontHeaderPtr ;

END DiskFont.
